/**
 * 上海中赢金融信息服务有限公司
 * Copyright (c) 2017-2027 Chinazyjr,Inc.All Rights Reserved.
 */
package com.sys.midware.hbase.hcore.query;

import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.hadoop.hbase.filter.FilterList;

import com.sys.midware.hbase.hcore.Optimize.QueryOptimze;
import com.sys.midware.hbase.hcore.filter.HbaseFilter;
import com.sys.midware.hbase.model.HbaseRow;
/**
 * hbase查询参数
 * <b>ClassName：</b> HbaseQueryParam <br/>
 * <b>Description：</b> TODO <br/>
 * <b>@author：</b> mobing <br/>
 * <b>@date：</b> 2015年10月26日 下午8:11:44 <br/>
 * <b>@version: </b>  <br/>
 */
public class HbaseQueryParam {

    private int limit = -1;
    private byte[] startRow = null;
    private byte[] stopRow = null;
    private HbaseFilter filter = null;// single filter
    private List<HbaseFilter> filters = null;// muti-filter
    private LinkedBlockingQueue<HbaseRow> queue;
    private FilterList filterList = null;// muti-filter

    // 查询优化参数
    private QueryOptimze queryOptimze = null;

    public HbaseQueryParam(int limit, byte[] startRow, byte[] stopRow, HbaseFilter filter, List<HbaseFilter> filters) {
        super();
        this.limit = limit;
        this.startRow = startRow;
        this.stopRow = stopRow;
        this.filter = filter;
        this.filters = filters;
    }

    public HbaseQueryParam(byte[] startRow, byte[] stopRow, LinkedBlockingQueue<HbaseRow> queue, FilterList filterList) {
        this(-1, startRow, stopRow, null, null);
        this.queue = queue;
        this.filterList = filterList;
    }

    public HbaseQueryParam(byte[] startRow, List<HbaseFilter> filters) {
        this(-1, startRow, null, null, filters);
    }

    /**
     * @param limit
     * @param startRow
     * @param stopRow
     * @param filter
     */
    public HbaseQueryParam(int limit, byte[] startRow, byte[] stopRow, HbaseFilter filter) {
        this(limit, startRow, stopRow, filter, null);
    }

    /**
     * @param limit
     * @param startRow
     * @param stopRow
     * @param filters
     */
    public HbaseQueryParam(int limit, byte[] startRow, byte[] stopRow, List<HbaseFilter> filters) {
        this(limit, startRow, stopRow, null, filters);
    }

    /**
     * @param limit
     * @param startRow
     * @param stopRow
     */
    public HbaseQueryParam(int limit, byte[] startRow, byte[] stopRow) {
        this(limit, startRow, stopRow, null, null);
    }

    /**
     * @param limit
     * @param startRow
     */
    public HbaseQueryParam(byte[] startRow, int limit) {
        this(limit, startRow, null, null, null);
    }

    /**
     * @param startRow
     * @param stopRow
     */
    public HbaseQueryParam(byte[] startRow, byte[] stopRow) {
        this(-1, startRow, stopRow, null, null);
    }

    /**
     * single filter
     *
     * @param filter
     */
    public HbaseQueryParam(HbaseFilter filter) {
        this(-1, null, null, filter, null);
    }

    /**
     * muti-filter
     *
     * @param filters
     */
    public HbaseQueryParam(List<HbaseFilter> filters) {
        this(-1, null, null, null, filters);
    }

    public HbaseQueryParam(byte[] start_rowkey, byte[] stop_rowkey, FilterList filterList2) {
        this(-1, start_rowkey, stop_rowkey, null, null);
        this.filterList = filterList2;
    }

    public HbaseQueryParam() {
    }

    public HbaseFilter getFilter() {
        return filter;
    }

    public List<HbaseFilter> getFilters() {
        return filters;
    }

    public int getLimit() {
        return limit;
    }

    public byte[] getStartRow() {
        return startRow;
    }

    public byte[] getStopRow() {
        return stopRow;
    }


    public LinkedBlockingQueue<HbaseRow> getQueue() {
        return queue;
    }

    public void setQueue(LinkedBlockingQueue<HbaseRow> queue) {
        this.queue = queue;
    }

    public FilterList getFilterList() {
        return filterList;
    }

    public void setFilterList(FilterList filterList) {
        this.filterList = filterList;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((filter == null) ? 0 : filter.hashCode());
        result = prime * result + ((filters == null) ? 0 : filters.hashCode());
        result = prime * result + (int) (limit ^ (limit >>> 32));
        result = prime * result + ((startRow == null) ? 0 : startRow.hashCode());
        result = prime * result + ((stopRow == null) ? 0 : stopRow.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        HbaseQueryParam other = (HbaseQueryParam) obj;
        if (filter == null) {
            if (other.filter != null)
                return false;
        } else if (!filter.equals(other.filter))
            return false;
        if (filters == null) {
            if (other.filters != null)
                return false;
        } else if (!filters.equals(other.filters))
            return false;
        if (limit != other.limit)
            return false;
        if (startRow == null) {
            if (other.startRow != null)
                return false;
        } else if (!startRow.equals(other.startRow))
            return false;
        if (stopRow == null) {
            if (other.stopRow != null)
                return false;
        } else if (!stopRow.equals(other.stopRow))
            return false;
        return true;
    }


    public QueryOptimze getQueryOptimze() {
        return queryOptimze;
    }

    public void setQueryOptimze(QueryOptimze queryOptimze) {
        this.queryOptimze = queryOptimze;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public void setStartRow(byte[] startRow) {
        this.startRow = startRow;
    }

    public void setStopRow(byte[] stopRow) {
        this.stopRow = stopRow;
    }

    public void setFilter(HbaseFilter filter) {
        this.filter = filter;
    }

    public void setFilters(List<HbaseFilter> filters) {
        this.filters = filters;
    }

}
